<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Controller;

use App\Constants\SuccessCode;
use App\Model\FinancePackage;
use App\Request\SettingIdRequest;
use App\Request\SettingUpdateRequest;
use App\Resource\BaseResource;
use App\Service\RateServer;
use Hyperf\HttpServer\Contract\RequestInterface;

class Setting extends AbstractController
{
    public function index(SettingIdRequest $request)
    {
        $setting = \App\Model\Setting::find($request->input('id'));

        return new BaseResource(SuccessCode::SUCCESS, $setting);
    }

    public function setSetting(SettingUpdateRequest $request)
    {
        \App\Model\Setting::find($request->input('id'))->update([
            'content' => $request->input('content', ''),
            'config' => $request->input('config'),
        ]);

        return new BaseResource();
    }

    public function getActivityConfig(RequestInterface $request)
    {
        $topUpSettin = \App\Model\Setting::find(\App\Model\Setting::ACTIVITY_TOP_UP)->config;
        $detailSettin = \App\Model\Setting::find(\App\Model\Setting::ACTIVITY_DETAIL)->config;
        return new BaseResource(SuccessCode::SUCCESS, [

            'activity_amount' => $topUpSettin['amount'],
            'activity_discount' => $topUpSettin['discount'],
            'activity_detail' => $detailSettin['detail'],
            'rate' => (new RateServer())->newRate(),
        ]);
    }
}
